package com.ohuang.wallpapermanager.compose

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column

import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.ohuang.wallpapermanager.ui.theme.color333
import com.ohuang.wallpapermanager.ui.theme.colorfff

@Composable
fun TipDialog(
    title: String,
    content: String,
    btnString: String = "确定",
    cancelString: String = "取消",
    properties: DialogProperties = DialogProperties(
        dismissOnBackPress = false,
        dismissOnClickOutside = false
    ),
    confirmClick: () -> Unit,
    onDismissRequest: () -> Unit
) {

    Dialog(
        onDismissRequest = onDismissRequest,
        properties = properties,
        content = {
            Column(
                modifier = Modifier
                    .width(300.dp)
                    .background(colorfff, shape = RoundedCornerShape(8.dp)),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Spacer(modifier = Modifier.height(10.dp))
                Text(
                    text = title, fontSize = 16.dp2sp(), color = color333
                )
                Spacer(modifier = Modifier.height(10.dp))
                Box(
                    modifier = Modifier
                        .fillMaxWidth()
                        .heightIn(min = 50.dp, max = 300.dp)
                        .padding(horizontal = 8.dp),
                    contentAlignment = Alignment.Center
                ) {
                    Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
                        Text(
                            text = content,
                            fontSize = 14.dp2sp(),
                            color = color333,
                            modifier = Modifier
                                .fillMaxWidth()
                                .wrapContentHeight(),
                            textAlign = TextAlign.Center
                        )
                    }

                }
                Spacer(modifier = Modifier.height(10.dp))
                Box(
                    modifier = Modifier
                        .width(250.dp)
                        .wrapContentHeight()
                ) {
                    Button(modifier = Modifier
                        .align(Alignment.CenterEnd)
                        .padding(end = 10.dp), onClick = {
                        confirmClick()
                    }) {
                        Text(text = btnString, fontSize = 16.dp2sp(), color = Color.White)
                    }
                    Button(modifier = Modifier
                        .align(Alignment.CenterStart)
                        .padding(start = 10.dp), onClick = {
                        onDismissRequest()
                    }) {
                        Text(text = cancelString, fontSize = 16.dp2sp(), color = Color.White)
                    }
                }
                Spacer(modifier = Modifier.height(10.dp))
            }
        }

    )
}